package handler

import (
	"awesomeProject/app/request"
	"awesomeProject/app/response"
	"awesomeProject/app/service"
	"awesomeProject/app/verify"
	"awesomeProject/util"
	"github.com/gin-gonic/gin"
)

type OrderItemOverViewHandler struct{}

var (
	orderItemOverviewSrv service.OrderItemOverviewSrv
)

func (o *OrderItemOverViewHandler) ItemOverView(ctx *gin.Context) {
	// 表单验证
	var req request.OrderItemOverview
	_ = ctx.Bind(&req)
	if err := verify.OrderItemOverview(&req); err != nil {
		response.Result(ctx, response.ErrInvalidParam.SetMsg(err.Error()))
		return
	}
	// 店铺权限
	user := util.CurrentLogin(ctx)
	var shopIds []uint
	if !user.SuperAdmin {
		shopIds = user.ShopIds
		if req.ShopId > 0 && !util.Contains(shopIds, req.ShopId) {
			response.Result(ctx, response.ErrForbidden.SetMsg("无权操作店铺数据"))
			return
		}
	}
	response.Result(ctx, orderItemOverviewSrv.ItemOverview(req))
	return
}
